home *** CD-ROM | disk | FTP | other *** search
- /*
- * DoLine.c
- *
- * Where all the action is
- */
-
- #include <ctype.h>
- #include <string.h>
- #include <stdio.h>
-
- #define Boolean char
-
- Boolean DoLine ( unsigned char * line ) ;
- void DoneLine ( void ) ;
-
- static FILE * outfile = NULL ;
- static Boolean lastWas = 0 ;
-
-
- static unsigned char *
- space ( unsigned char * pos ) {
-
- while ( * pos && isspace ( * pos ) ) {
- pos ++ ;
- }
- return pos ;
- }
-
-
- static char tok [ 100 ] ;
- static char new_name [ 100 ] ;
- static char old_name [ 100 ] ;
- Boolean isPrivate ;
-
-
- static unsigned char *
- nonspace ( unsigned char * pos ) {
-
- while ( * pos && ! isspace ( * pos ) ) {
- pos ++ ;
- }
- return pos ;
- }
-
-
- static unsigned char *
- token ( unsigned char * pos ) {
-
- unsigned char * npos ;
-
- pos = space ( pos ) ;
- npos = nonspace ( pos ) ;
- BlockMove ( pos , tok , npos - pos ) ;
- tok [ npos - pos ] = 0 ;
- return npos ;
- }
-
-
- static void
- output ( Boolean priv , char * newname , char * oldname , unsigned char * ret ) {
-
- if ( ! outfile ) {
- outfile = fopen ( " CLASSLIST" , "w" ) ;
- }
- if ( outfile ) {
- fprintf ( outfile , "%s %s %s\n" , newname , oldname , priv ?
- "private" : "public" ) ;
- }
- sprintf ( ( char * ) ret , "DECLARE_%s ( %s , %s )\r" , priv ? "PRIVATE" : "PUBLIC" ,
- newname , oldname ) ;
- }
-
-
- Boolean
- DoLine ( unsigned char * line ) {
-
- unsigned char * ret = line + 1 ;
-
- isPrivate = 1 ;
-
- line [ 1 + * line ] = 0 ;
- line ++ ;
- line = token ( line ) ;
- if ( ! * line && ! tok [ 0 ] ) {
- return false ; /* Ignore empty lines */
- }
- if ( lastWas ) {
- lastWas = 0 ;
- if ( ! strcmp ( tok , "{" ) ) { /* Don't like trailing braces myself...*/
- line [ -1 ] = ' ' ;
- return true ;
- }
- }
- if ( strcmp ( "class" , tok ) ) {
- if ( strcmp ( "struct" , tok ) ) {
- return 0 ;
- }
- isPrivate = 0 ;
- }
- line = token ( line ) ;
- strcpy ( new_name , tok ) ;
- line = token ( line ) ;
- if ( strcmp ( ":" , tok ) ) {
- return 0 ;
- }
- line = token ( line ) ;
- if ( ! strcmp ( ( char * ) tok , "public" ) ) {
- line = token ( line ) ;
- isPrivate = 0 ;
- } else if ( ! strcmp ( ( char * ) tok , "private" ) ) {
- line = token ( line ) ;
- isPrivate = 1 ;
- }
- strcpy ( old_name , tok ) ;
- output ( isPrivate , new_name , old_name , ret ) ;
- ret [ -1 ] = strlen ( ( char * ) ret ) ;
- lastWas = 1 ;
- return 1 ;
- }
-
-
- void
- DoneLine ( void ) {
-
- if ( outfile ) {
- fclose ( outfile ) ;
- }
- }
-
-